package com.example.demo.java8.CompletableFuture;

import cn.hutool.core.thread.NamedThreadFactory;
import org.springframework.stereotype.Service;

import java.util.concurrent.*;

@Service
public class CompletableFutureService {

    public void old() throws ExecutionException, InterruptedException {
        ExecutorService executorService = new ThreadPoolExecutor(3,
                3, 0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(),
                new NamedThreadFactory("demo-customer-thread-pool", false));

        Future<String> future1 = executorService.submit(() -> {
            Thread.sleep(1000);
            return "结束了" + Thread.currentThread().getName();
        });
        Future<String> future2 = executorService.submit(() -> {
            Thread.sleep(1000);
            return "结束了" + Thread.currentThread().getName();
        });
        Future<String> future3 = executorService.submit(() -> {
            Thread.sleep(1000);
            return "结束了" + Thread.currentThread().getName();
        });
        System.out.println(future1.isDone());
        System.out.println(future1.get());
        System.out.println(future2.isDone());
        System.out.println(future2.get());
        System.out.println(future3.isDone());
        System.out.println(future3.get());
    }
}
